z=[]
a=input()
b=a.split()
if b[0]=="zero" or b[0]=="one" or b[0]=="two" or b[0]=="three" or b[0]=="four" or b[0]=="five" or b[0]=="six" or b[0]=="seven" or b[0]=="eight" or b[0]=="nine":
    z.append(b[0])
else:
    print("Wrong input")
    exit
if b[1]=="zero" or b[1]=="one" or b[1]=="two" or b[1]=="three" or b[1]=="four" or b[1]=="five" or b[1]=="six" or b[1]=="seven" or b[1]=="eight" or b[1]=="nine":
    z.append(b[1])
else:
    print("Wrong input")
    exit
if b[2]=="zero" or b[2]=="one" or b[2]=="two" or b[2]=="three" or b[2]=="four" or b[2]=="five" or b[2]=="six" or b[2]=="seven" or b[2]=="eight" or b[2]=="nine":
    z.append(b[2])
else:
    print("Wrong input")
    exit
for i in range(len(z)):
    if z[i]=="zero":
        z[i]=0
    elif z[i]=="one":
        z[i]=1
    elif z[i]=="two":
        z[i]=2
    elif z[i]=="three":
        z[i]=3
    elif z[i]=="four":
        z[i]=4
    elif z[i]=="five":
        z[i]=5
    elif z[i]=="six":
        z[i]=6
    elif z[i]=="seven":
        z[i]=7
    elif z[i]=="eight":
        z[i]=8
    elif z[i]=="nine":
        z[i]=9
d=z[0]*100+z[1]*10+z[2]

def norm(d: int):
    for i in range(2,d):
        if d%i==0:
            return False
    return True

e=d
f=d

while not norm(e):
    e=e-1

while not norm(f):
    f=f+1

if d-e>f-d:
    print(f)
else:
    print(e)
